const express = require('express')
const mockdata = require('./api/index')

const app = express()

const port = 13322

app.use(express.json())

app.use((req, res, next) => {
  console.log(`${req.method} ${req.path}`)
  next()
})

mockdata.forEach((item) => {
  app[item.type]('/local' + item.url, (req, res) => {
    res.send(item.response(req, res))
  })
})

console.log('运行了')
app.listen(port, () => {
  console.log(`mock server is running at http://localhost:${port}/local`)
})
